package logic

import (
	"context"
	"house-rent-hub/models"

	"house-rent-hub/houserpc/houserpc"
	"house-rent-hub/houserpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type LoginLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic {
	return &LoginLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 登录
func (l *LoginLogic) Login(in *houserpc.LoginRequest) (*houserpc.LoginResponse, error) {
	// todo: add your logic here and delete this line

	var user models.User
	if err := user.FindUser(models.DB, in.UserId); err != nil {
		return nil, err
	}

	return &houserpc.LoginResponse{
		Username: user.Mobile,
		Password: user.Password,
	}, nil
}
